package edu.vt.ece.rt.dstm.contention;

import java.util.Date;

import edu.vt.ece.rt.dstm.Context;

public class Timestamp extends AbstractContentionPolicy{

	@Override
	public void init(Context context) {
		context.contentionMetadata = new Date().getTime();
	}
	
	@Override
	public int resolve(Context context1, Context context2) {		
		Long startTime1 = (Long)context1.contentionMetadata;
		Long startTime2 = (Long)context2.contentionMetadata;
		
		if(startTime1==null || startTime2!=null && startTime1 > startTime2){			
			return +1;
		}
		else{
			return -1;
		}
	}

	@Override
	public void open(Context context) {}
}
